#include "InetAddress.h"

// 监听的fd
InetAddress::InetAddress(const std::string &ip, uint16_t port)
{
    addr_.sin_family = AF_INET;
    addr_.sin_addr.s_addr = inet_addr(ip.c_str());
    addr_.sin_port = htons(port);
}

// 客户端连接上来的fd
InetAddress::InetAddress(const sockaddr_in addr)
{
    addr_ = addr;
}


InetAddress::~InetAddress()
{

}

// 返回字符串表示的地址
const char* InetAddress::ip()
{
    return inet_ntoa(addr_.sin_addr);
}

// 返回证书表示的端口
uint16_t InetAddress::port()
{
    return ntohs(addr_.sin_port);
}

// 返回addr_成员的地址，转换成了sockaddr
const sockaddr* InetAddress::addr()
{
    return (struct sockaddr *)&addr_;
}